<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Tpl extends Controller_Autorization {

	private $_header;
	private $_header_menu;
	private $_footer;
	protected $_page;
	//private $_data;

	public function before()
	{
		parent::before();
/*		$this->_data['controller'] = $this->request->controller();
		$this->_data['action'] = $this->request->action();
		$this->_data['id'] = $this->request->param('id',NULL);
*/	}


	public function after()
	{
// 		if ($this->is_allowed($this->r->sMembers('user_groups:'.$this->user->id),'read'))
// 		{
 		if ($this->_data['type']=='short' AND Kohana::find_file('views', $this->_data['controller'].'/short/'.$this->_data['action'])!==FALSE)
 		{
			$this->_page = View::factory($this->_data['controller'].'/short/'.$this->_data['action'],$this->_data);
		}
		else
		{
			$this->_page = View::factory($this->_data['controller'].'/'.$this->_data['action'],$this->_data);
		}

// 		}
// 		else
// 		{
// 			$this->_page = View::factory('page/bootstrap_denied');
// 		}
		if ($this->request->is_ajax())
		{
			
			$this->response->headers('Cache-Control', 'no-cache,no-store,max-age=0,must-revalidate');
        	$this->response->headers('Pragma', 'no-cache');
			if($this->_data['type']=='full')
			{
				$this->response->body($this->_header.$this->_header_menu.$this->_page.$this->_footer);
			}
			elseif ($this->_data['type']=='short')
			{
				$this->response->headers('Content-Type', 'text/json charset=utf-8');
				$this->response->body($this->_page);
			}
		}
		else
		{
			$this->_header = View::factory('law/blocks/header_bs',$this->_data);
			$this->_header_menu = View::factory('law/blocks/header_bs_menu',$this->_data);
			$this->_footer = View::factory('law/blocks/footer_bs',$this->_data);
			$this->response->body($this->_header.$this->_header_menu.$this->_page.$this->_footer);
		}
		parent::after();
	}



} // End Tpl
